var express = require('express');
var router = express.Router();
const alipaySdk = require('../util/alipayUtil')
const alipay = require("alipay-sdk");

const AlipayFromData = alipay.AlipayFormData;
 

/* GET home page. */
router.get('/', function(req, res, next) {
  res.render('index', { title: 'Express',btn:"我是按钮" });
});
 
router.post('/pay',async (req, res) => {
    // 前端给后端的数据（订单号，金额，商品描述等信息）
    let orderId = req.body.orderId;
    let orderMoney = req.body.orderMoney;
    let orderTitle = req.body.orderTitle;
    let orderInfo = req.body.orderInfo;
    
    
const result = await alipaySdk.pageExec("alipay.trade.page.pay","get", {
    bizContent: {
      store_id: "WH_000001",
      time_expire: "2024-06-07+10:05:01",
      extend_params: {
        sys_service_provider_id: "2088511833207846",
        hb_fq_seller_percent: "100",
        hb_fq_num: "3",
        industry_reflux_info:
          '{\\"scene_code\\":\\"metro_tradeorder\\",\\"channel\\":\\"xxxx\\",\\"scene_data\\":{\\"asset_name\\":\\"ALIPAY\\"}}',
        specified_seller_name: "XXX的跨境小铺",
        royalty_freeze: "true",
        card_type: "S0JP0000",
      },
      subject: "Iphone6+16G",
      request_from_url: "https://",
      product_code: "FAST_INSTANT_TRADE_PAY",
      qr_pay_mode: "1",
      qrcode_width: "100",
      integration_type: "PCWEB",
      goods_detail: {
        0: {
          goods_name: "ipad",
          alipay_goods_id: "20010001",
          quantity: "1",
          price: "2000",
          goods_id: "apple-01",
          goods_category: "34543238",
          categories_tree: "124868003|126232002|126252004",
          show_url: "http://www.alipay.com/xxx.jpg",
        },
      },
      merchant_order_no: "20161008001",
      sub_merchant: {
        merchant_id: "2088000603999128",
        merchant_type: "alipay",
      },
      invoice_info: {
        key_info: {
          tax_num: "1464888883494",
          is_support_invoice: "true",
          invoice_merchant_name: "ABC|003",
        },
        details:
          '[{"code":"100294400","name":"服饰","num":"2","sumPrice":"200.00","taxRate":"6%"}]',
      },
      out_trade_no: "20150320010101001",
      ext_user_info: {
        cert_type: "IDENTITY_CARD",
        cert_no: "362334768769238881",
        name: "李明",
        mobile: "16587658765",
        min_age: "18",
        need_check_info: "F",
        identity_hash:
          "27bfcd1dee4f22c8fe8a2374af9b660419d1361b1c207e9b41a754a113f38fcc",
      },
      total_amount: orderMoney,
      business_params: '{"mc_create_trade_ip":"127.0.0.1"}',
      promo_params: '{"storeIdType":"1"}'
    },
  });
  res.json({
    code:200,
    result
  })
})






module.exports = router;
